package com.jonniespratley.codegen.vo
{
	 
	import mx.collections.ArrayCollection;


	[Bindable]
	public class FileVO
	{

	//	public var aFile:String;
		public var aFilename:String;
		public var aPath:String;
		public var aExt:String;
		public var isDir:String;
		public var isFile:String;
		public var isWritable:String;
		public var isReadable:String;

		public var fileFullPath:String;
		public var aChildren:ArrayCollection;

		public function  FileVO( obj:Object = null )
		{
			if ( obj != null )
			{
				this.aFilename = obj['filename'];
				this.aPath = obj['path'];
				this.aExt = obj['ext'];
				this.isDir = obj['isDir'];
				this.isFile = obj['isFile'];
				this.isWritable = obj['isWritable'];
				this.isReadable = obj['isReadable'];

				if ( obj['children'] )
				{
					//set the fields comming back as an Array
					var tempArray:Array = obj['children'] as Array;

					//create a temp arraycollection so return to the aFields
					var tempAc:ArrayCollection = new ArrayCollection();

					//loop through every string in the fields array
					for ( var s:String in tempArray )
					{
						//for each object add it to the temp collection
						tempAc.addItem( new FileVO( tempArray[ s ] ) );
					}
					//set the array collection to the build one of value objects
					this.aChildren = tempAc;
				}
			}
		}

		public function get label():String
		{
			return this.aFilename;
		}

		public function get children():Array
		{
			var a:Array = [];
			if ( aChildren != null )
			{
				return this.aChildren.toArray();
			}
			return null;
		}

		/*public function get icon():Class
		{
			return MimeTypeIcons.getMimeIcon( this.aExt );
		}*/
	}
}